package com.practise;

import java.util.ArrayList;
import java.util.HashMap;

//1.现存在一个字符串数组,数组元素自己给出
//2.统计该数组所有元素中,每个元素出现的次数
//例: String[] arr = {"abc","ab"}
//统计得出: a=2  b=2  c=1
public class PractiseDemo1 {
    public static void main(String[] args) {
        String[] arr = {"abc","ab"};
        ArrayList list=new ArrayList();
        for (String s : arr) {
            char[] chars = s.toCharArray();
            for (char aChar : chars) {
                list.add(aChar);
            }
        }
        HashMap<Character, Integer> ha = new HashMap<>();
        for (Object o : list) {
            if (ha.containsKey(o)) {
                Integer integer = ha.get(o);
                integer++;
                ha.put((Character) o, integer);
            }else {
                ha.put((Character) o, 1);
            }
        }
        System.out.println("ha = " + ha);
        }
    }

